package com.mc.serviceImpl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mc.dao.ArticleMapper;
import com.mc.model.Article;
import com.mc.service.ArticleService;

@Service
public class ArticleServiceImpl implements ArticleService {

	@Autowired
	private ArticleMapper articleMapper;
	
	@Override
	public int deleteByPrimaryKey(Integer id) {
		return articleMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Article record) {
		return articleMapper.insert(record);
	}

	@Override
	public int insertSelective(Article record) {
		return articleMapper.insertSelective(record);
	}

	@Override
	public Article selectByPrimaryKey(Integer id) {
		return articleMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(Article record) {
		return articleMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(Article record) {
		return articleMapper.updateByPrimaryKey(record);
	}

	@Override
	public List<Article> selectAll() {
		return articleMapper.selectAll();
	}

	@Override
	public List<Article> selectLimit(int start, int size) {
		if (start < 0)
			start = 0;
		return articleMapper.selectLimit(start, size);
	}

	@Override
	public long count() {
		return articleMapper.count();
	}

	@Override
	public Article selectByPrimaryKeyAndCascade(Integer id) {
		return articleMapper.selectByPrimaryKeyAndCascade(id);
	}

	@Override
	public List<Article> selectByMenuName(String menuName) {
		return articleMapper.selectByMenuName(menuName);
	}

	@Override
	public Set<String> getSubMenuNames(List<Article> articles) {
    	Set<String> subMenuNames = new HashSet<String>();
    	
    	for (Article ar : articles) {
			subMenuNames.add(ar.getMenuName());
		}
    	
    	return subMenuNames;
	}
}